<template>
    <div class="edit-popup">
        <el-dialog v-model="props.dialogFormVisible" width="500" :title="popupTitle" @close="handleClose">
            <el-form :model="formGet" v-if="props.titleDia == '1'">
                <el-form-item>
                    <el-input v-model="props.formGet.remark" />
                </el-form-item>
            </el-form>
            <el-form :model="formGet" v-if="props.titleDia == '2'">
                <el-form-item label="任务执行间隔范围" :label-width="formLabelWidth">
                    <el-input-number v-model="props.formGet.start_num" /> ~
                    <el-input-number v-model="props.formGet.end_num" />
                </el-form-item>
                <el-form-item label="任务执行间隔秒" :label-width="formLabelWidth">
                    <el-input v-model="props.formGet.command_num" />
                </el-form-item>
            </el-form>
            <el-form :model="formGet" v-if="props.titleDia == '3'">
                <el-form-item>
                    <el-radio-group v-model="formGet.radio1" class="ml-4">
                        <el-radio label="1" size="large">增加票数</el-radio>
                        <el-radio label="2" size="large">减少票数</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item>
                    <el-input v-model="props.formGet.name" placeholder="请输入票数" />
                </el-form-item>
            </el-form>
            <el-form :model="formGet" v-if="props.titleDia == '4'">
                <el-form-item label="每天票数" label-width="100px">
                    <el-input v-model="props.formGet.day_num" />
                </el-form-item>
                <el-form-item label="每小时票数" label-width="100px">
                    <el-input v-model="props.formGet.hour_num" />
                </el-form-item>
                <el-form-item label="每分钟票数" label-width="100px">
                    <el-input v-model="props.formGet.minute_num" />
                </el-form-item>
            </el-form>
            <template #footer>
                <span class="dialog-footer" v-if="props.titleDia !== '1'">
                    <el-button @click="handleClose">取 消</el-button>
                    <el-button type="primary" @click="handleSubmit">确 定</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>

<script lang="ts" setup name="zgVotesLogEdit">
import type { FormInstance } from 'element-plus'
import Popup from '@/components/popup/index.vue'
import {
    apiZgPlayerManagesConfigure,
    apiZgPlayerManagestChange,
    apiZgPlayerManagesBlacklist
} from '@/api/zg_player_manage'
import { timeFormat } from '@/utils/util'
import type { PropType } from 'vue'
const props = defineProps({
    titleDia: String,
    formGet: Object,
    dialogFormVisible: Boolean
})

const dialogFormVisible = ref(false)
const formLabelWidth = '140px'
const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const mode = ref('add')
// 表单数据
const formGet = props.formGet

// 弹窗标题
const title = ref<string>('')
const popupTitle = computed(() => {
    if (props.titleDia == '1') {
        title.value = '编辑备注, 是否继续?'
    } else if (props.titleDia == '2') {
        title.value = '人气配置'
    } else if (props.titleDia == '3') {
        title.value = '更改选手票数'
    } else if (props.titleDia == '4') {
        title.value = '编辑限制'
    }
    return title.value
})

// 提交按钮
const handleSubmit = async () => {
    await formRef.value?.validate()
    const data = { ...formGet }
    if (props.titleDia == '2') {
        title.value = '人气配置'
        await apiZgPlayerManagesConfigure(data)
    } else if (props.titleDia == '3') {
        title.value = '更改选手票数'
        await apiZgPlayerManagestChange(data)
    } else if (props.titleDia == '4') {
        title.value = '编辑限制'
        await apiZgPlayerManagesBlacklist(data)
    }
    popupRef.value?.close()
    // emit('success')
}

// //打开弹窗
// const open = (type = 'add') => {
//     mode.value = type
//     popupRef.value?.open()
// }

// 关闭回调
const handleClose = () => {
    emit('close')
}

defineExpose({})
</script>
